package myList;

import java.util.ArrayList;
import java.util.List;

public class ListDemo02 {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        //method1(list);
        //method2(list);
        //method3(list);
        method4(list);

    }

    private static void method4(List<String> list) {
        String s = list.set(1, "QQQ");
        System.out.println(s);
        System.out.println(list);
    }

    private static void method3(List<String> list) {
       //向集合指定位置添加元素
        list.add(1,"ddd");
        System.out.println(list);
    }

    private static void method2(List<String> list) {
        //删除指定元素并返回
        String remove = list.remove(0);
        System.out.println(remove);
        System.out.println(list);
    }

    private static void method1(List<String> list) {
        //获取指定索引元素
        String get = list.get(1);
        System.out.println(get);
    }


}
